/// <reference path="./typings/index.d.ts" />
'use strict';
const express = require('express'),
    config = require('./config/config'),
    glob = require('glob'),
    mongoose = require('mongoose');

mongoose.connect(config.db);
/**加载数据库连接 */
const db = mongoose.connection;
db.on('error', function() {
    throw new Error('unable to connect to database at ' + config.db);
});
/**加载models */
glob.sync(config.root + '/app/models/*.js')
    .forEach(function(model) {
        require(model);
    });
const app = express();

require('./config/express')(app, config);

app.listen(config.port, function() {
    console.log('Express server listening on port ' + config.port);
});